package com.cos.hospital.tool;

import com.cos.hospital.model.bean.PatientListBean;

import java.util.Comparator;
import java.util.Date;

/**
 * 以剩余时间来排序
 */
public class SurplusTimeComparator implements Comparator<PatientListBean.ItemsBean> {

    public int compare(PatientListBean.ItemsBean o1, PatientListBean.ItemsBean o2) {
        long l = System.currentTimeMillis() / 1000;
        String fldTreatmentStart1 = o1.getFldTreatmentStart();
        int fldTreatmentDuration1 = o1.getFldTreatmentDuration();
        Date date1 = UDate.strToDateSafety(fldTreatmentStart1);
        long delta1 = date1.getTime() / 1000 + fldTreatmentDuration1 * 60 - l;

        String fldTreatmentStart2 = o2.getFldTreatmentStart();
        int fldTreatmentDuration2 = o2.getFldTreatmentDuration();
        Date date2 = UDate.strToDateSafety(fldTreatmentStart2);
        long delta2 = date2.getTime() / 1000 + fldTreatmentDuration2 * 60 - l;
        if (delta1 <= 0) {
            return 1;
        }
        return Long.compare(delta1, delta2);
    }
}
